package fxbattle.fxgui;

/**
 * @author spina
 */

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.transform.Translate;
import javafx.scene.control.ScrollBar;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.geometry.Bounds;

// Need to rename this class.
public class ScrollableHexMap extends CustomNode {

    def boundary = 1;
	public var panelheight = 400;
	public var panelwidth = 450;
	public var background : Color = Color.BLACK; 
    public var content: Node[];
    // I got this from trial and error on the Mac. It's probably platform specific.
	def barwidth = 12;
	
    def clipRect = Rectangle {
		    		fill : bind background;
			        x: boundary,
			    	y: boundary,
			        width: bind panelwidth - boundary,
                    height: bind panelheight - boundary,
			    }
			    
	def vbar = ScrollBar {
	    translateY: boundary
	    translateX: bind panelwidth - barwidth
	    height: bind panelheight - boundary - barwidth - 8
	    vertical: true
	    value: 0 
	    max: bind contentBounds().height - panelheight;
	    min: 0
	}
	
	
	def hbar = ScrollBar {
	    translateX: boundary
	    translateY: bind panelheight - (barwidth * 2) + 4
	    width: bind panelwidth - boundary - barwidth
	    vertical: false
	    max: bind contentBounds().width - panelwidth;
	    min: 0
	}
    
    var contentContainer = Group{
        content: bind content
        transforms : [Translate{
	        			x : bind - hbar.value;
	        			y : bind - vbar.value;
					 }]
    }

    // TODO: Make this iterate over all the children and access the right bounds
    bound function contentBounds(): Bounds {
        var n : Node = content[0];
        n.boundsInParent
    }

    public override function create(): Node {
        return Group {
            clip: clipRect
            content: bind [contentContainer, hbar, vbar]
        };
    }
}